import os


def find_itstool_statements(root_dir, content):
    for foldername, _, filenames in os.walk(root_dir):
        for filename in filenames:
            file_path = os.path.join(foldername, filename)
            try:
                with open(file_path, 'r', encoding='utf-8') as file:
                    if content in file.name:
                        print(f"Found in {file_path} with the key '{content}':")
                    for line_number, line in enumerate(file, 1):
                        if content in line:
                            print(f"Found in {file_path} at line {line_number}:")
                            print(line.strip())
            except (UnicodeDecodeError, PermissionError):
                # Skip files that can't be read due to encoding issues or permission errors
                continue

# 使用示例
root_directory = 'E:\dependency-analysis\package-mapping-results\maven_raw_testdata\\narayana\\narayana-5.3.3.Final'
content = '<profile>'
find_itstool_statements(root_directory, content)

